package me.ao5dolydemo5;

public class Test {
    public static void main(String[] args) {
//        Person p1 = new Person("张三", 18);
//        Dog d = new Dog("黄色", 1);
//        p1.keeppet(d, "骨头");
//        Cat c = new Cat("黄色", 2);
//        p1.keeppet(c, "鱼");
        Person p2 = new Person("张三", 18);
        Dog d = new Dog("黄色", 1);
        p2.keeppet(d, "骨头");
        Cat c = new Cat("黄色", 2);
        p2.keeppet(c, "鱼");
    }
}

class Animal {
    private String color;
    private int age;

    public Animal() {
    }

    public Animal(String color, int age) {
        this.color = color;
        this.age = age;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getColor() {
        return color;
    }

    public int getAge() {
        return age;
    }

    public void eat(String something) {
        System.out.println("动物在吃" + something);
    }
}

class Dog extends Animal {
    public Dog() {
    }

    public Dog(String color, int age) {
        super(color, age);
    }

    public void eat(String something) {
        System.out.println(getAge() + "岁的" + getColor() + "狗在吃" + something);
    }

    public void lookhome() {
        System.out.println("狗在看家");
    }
}

class Cat extends Animal {
    public Cat() {
    }

    public Cat(String color, int age) {
        super(color, age);
    }

    public void eat(String something) {
        System.out.println(getAge() + "岁的" + getColor() + "猫在吃" + something);
    }

    public void catchmouse() {
        System.out.println("猫在抓老鼠");
    }
}

class Person {
    private String name;
    private int age;

    public Person() {
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    //    public void keeppet(Dog d, String something) {
//        System.out.println("年龄为" + age + "岁的" + name + "养了" + d.getAge() + "岁的" + d.getColor() + "狗");
//        d.eat(something);
//    }
//
//    public void keeppet(Cat c, String something) {
//        System.out.println("年龄为" + age + "岁的" + name + "养了" + c.getAge() + "岁的" + c.getColor() + "猫");
//        c.eat(something);
//    }
    public void keeppet(Animal a, String something) {
        if (a instanceof Dog d) {
            System.out.println("年龄为" + age + "岁的" + name + "养了" + a.getAge() + "岁的" + a.getColor() + "的狗");
            d.eat(something);
        } else if (a instanceof Cat c) {
            System.out.println("年龄为" + age + "岁的" + name + "养了" + a.getAge() + "岁的" + a.getColor() + "的猫");
            c.eat(something);
        } else {
            System.out.println(0);
        }


    }
}
